package info.sean.controller;

import info.sean.domain.User;
import info.sean.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;


import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("/user")

public class UseraController {

    @Autowired
    UserService userService;


    @PostMapping("/logining")
    public String login(String username, String password , Model model, HttpSession session){
        User user = userService.loging(username, password);
        System.out.println("user"+user);
        if (user==null){

            model.addAttribute("errorMessage","用户名或密码错误");
            return "/login.jsp";
        }
          session.setAttribute("user",user);
        return "redirect:/account/findAll";
    }
}
